package dgut.lgc.bean;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class DateRecord {

    private int year;
    private int month;
    private int day;
    private final List<Integer> leapDys = Arrays.asList(31,29,31,30,31,30,31,31,30,31,30,31);
    private final List<Integer> ordinaryDys = Arrays.asList(31,29,31,30,31,30,31,31,30,31,30,31);

    public DateRecord(int year,int month,int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public Boolean isLeapYear() {
        return this.year%4==0||this.year%100==0&&this.year%400!=0;
    }

    public void addOneDay() {

        List<Integer> days = new ArrayList<>(isLeapYear()?leapDys:ordinaryDys);

        this.day += 1;
        if (this.day > days.get(this.month - 1)) {
            this.month += 1;
            this.day = 1;
        }
        if (this.month > 12) {
            this.year += 1;
            this.month = 1;
        }
    }

    public void add(int days) {
        while (days>0){
            this.addOneDay();
            days -= 1;
        }
    }

    public String toString() {
        return this.year + "-" + (this.month<10?"0"+this.month:this.month) + "-" + (this.day<10?"0"+this.day:this.day);
    }
}
